package interpreter.main.express;

import interpreter.main.context.Context;

public class PrimitiveExpression implements IExpressions {
    private Context context;
    //节点名称
    private String tokenName;
    //节点内容
    private String text;

    public PrimitiveExpression(Context context) {
        this.pares(context);
    }

    /**
     * 解析
     *
     * @param context
     */
    @Override
    public void pares(Context context) {
        this.context = context;
        this.tokenName = this.context.getCurrentToken();
        this.context.next();
        if ("PRINTLN".equals(this.tokenName)) {
            this.text = this.context.getCurrentToken();
            this.context.next();
        }
    }

    /**
     * 执行方法
     */
    @Override
    public void interpret() {
        //首先获取当前节点内容
        if ("PRINTLN".equals(tokenName)) {
            //获得内容信息
            //打印内容
            System.out.println(this.context.getTokenContent(this.text));
        }
    }
}
